Developer Documentation
PATH  WebObjects 4.5 Documentation > Getting Started With Direct to Java Client

   

When to Write Custom Rules

Custom rules are used for a variety of tasks, including the following:

However, the most common reason to write custom rules is to configure many different controllers with one simple rule. Right justifying numeric text fields as described earlier in this section is a good example. It's possible to use the Assistant to accomplish the same thing as the custom rule, but using the Assistant has a drawback in this scenario: Each text field has to be configured individually, which is time consuming and error prone. Not only is it easy to overlook a text field; but if the model changes in the future, you have to remember to configure any newly added numeric text fields.

As another example, suppose you want to set the minimum width of all an application's windows. Again this is something you can do in the Assistant, but you have to do it individually for each window. The following single rule can accomplish the same thing:

In this rule, it's necessary to specify what kind of controller the rule system is working on. Many different controllers have the attribute minimumWidth, so to limit this rule's scope to setting the minimum width of only windows, you must restrict the rule to firing only when the rule system is working on window controllers.

The rule system's D2WContext stores the type of controller it's working on and makes the type available with the key controllerType. The possible values for controllerType are:

Note:  You can use any state information stored in the D2WContext in the condition (lhs) of a rule. For more information on the entries in a D2WContext, see the section Server Side XML Generation.


© 1999 Apple Computer, Inc. – (Draft. Last updated 05 Jan 00)